-
Couldn't load subscription status.
- Fork 11.6k
[13.x] Cache::touch() & Store::touch() for TTL Extension
#55954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[13.x] Cache::touch() & Store::touch() for TTL Extension
#55954
Conversation
|
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
52bc6b1 to
73fa810
Compare
Cache::touch() & Store::touch() for TTL Extension
|
This is pretty cool. One caveat though is the addition of the method to the cache repository contract which will be a breaking change to any existing implementations. For that reason we may probably need to target this to |
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
73fa810 to
485efd0
Compare
|
@taylorotwell Done. |
| /** | ||
| * Set the expiration of a cached item; null TTL will retain indefinitely. | ||
| */ | ||
| public function touch(string $key, DateTimeInterface|DateInterval|int|null $ttl = null): bool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a method to a public interface is a major breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is targetting master now, should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, I could drop the notation from the Cache facade and the method from the Repository interface, but would still need to do something like method_exists and return false or throw an exception that the driver doesn't support touch() if we dropped it from the Store interface. That would allow it to target 12.x, but not sure that's necessarily better than targeting master.
I'm open to whatever y'all think, of course.
| /** | ||
| * Set the expiration of a cached item. | ||
| */ | ||
| public function touch(string $key, int $ttl): bool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a method to a public interface is a major breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is targetting master now, should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be removed from the Store interface, but that would require doing something like method_exists and return false or throw an exception that the driver doesn't support the feature in Repository::touch(). That would allow it to target 12.x, but not sure that's necessarily better than targeting master.
I'm open to whatever y'all think, of course.
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
Cache::touch() & Store::touch() for TTL ExtensionCache::touch() & Store::touch() for TTL Extension
|
@yitzwillroth This is a very nice addition, am all for it. One thing i noticed is that no code have been changed to the tags repositories? Does this new cache method work out of the box with cache tags? |
|
Thanks! |
This pull request introduces the
Cache::touch()method, addressing a fundamental challenge that developers encounter frequently: extending cache TTL without the overhead of retrieving and re-storing data.Basic Usage:
Simplifies Common Patterns:
Cache:touch()&$store->touch()returntrueon success andfalsewhen the item is not found in the cache.Cache:touch()accepts anint,DateTimeInterface, orDateIntervalfor extending the TTL;nullwill extend the TTL indefinitely;$store->touch()requires anint(conversion is handled in theRepository.This pull request includes the following:
CacheFacadeRepositoryandStoreContractsApcStore,ArrayStore,DatabaseStore,DynamoDbStore,FileStore,MemcachedStore,MemoizedStore,NullStore, andRedisStorePrimary Use Cases
1. Activity-Based Cache Extension
2. Cache Warming Maintenance
3. Progressive Cache Strategies
Real-World Scenarios
E-commerce Product Caching
API Response Caching
Performance Benefits
Network/Storage Efficiency
GET+SEToperations, uses singleEXPIREcommandSELECT+UPDATE, uses singleUPDATEon timestampTOUCHcommand instead ofGET+SETMemory Efficiency
Cache::touch($key, $seconds)is immediately understandabletouch()command developers know💁🏼♂️ The author is available for hire -- inquire at yitzwillroth@gmail.com.